<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>选项卡右键菜单</title>

	<script type="text/javascript" src="../js/jquery-1.8.3.js" ></script>
	
	<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
	
	<script type="text/javascript" src = "../js/easyui/locale/easyui-lang-zh_CN.js"></script>
	
	<link id="easyuiTheme" type="text/css" rel="stylesheet" href="../js/easyui/themes/default/easyui.css" />
	
	<link type="text/css" rel="stylesheet" href = "../js/easyui/themes/icon.css" />
	
	<!-- 引入ztree-->
	<script type="text/javascript" src="../js/ztree/jquery.ztree.all-3.5.js"></script>
	<link type="text/css" rel="stylesheet" href = "../js/ztree/zTreeStyle.css" />
	
	<script type="text/javascript">
		$(function(){
			/*开启简单数据支持*/
			var setting = {
				data:{
					simpleData:{
						enable:true //支持json数据格式；
					}
				},callback:{
					onClick:function(event,treeId,treeNode,clickFlag){
						
						var content = '<div style="width:100%;height:100%;overflow:hidden;">'
								+ '<iframe src="'
								+ treeNode.page
								+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';
								
						//判断树形菜单是否存在，如果存在，不切换，如果不存在，打开选项卡；
						
						//判断树形菜单是否存在：
						//alert(treeNode);
						if(treeNode.page != undefined && treeNode.page!=""){
							//判断选显卡是否存在：
							if($("#mytabs").tabs('exists',treeNode.name)){
								$("#mytabs").tabs('select',treeNode.name);
							}else{
								$("#mytabs").tabs('add',{
									title:treeNode.name,
									content: content,
									closable :true
								});
							}
						}
					}
				}
			};
			//2.树形菜单的数据
			var zNodes = [
			{id:1,pId:0,name:"父节点一"},
			{id:2,pId:0,name:"父节点二"},
			{id:11,pId:1,name:"父一的1子节点"},
			{id:12,pId:1,name:"父一的2子节点"},
			{id:21,pId:2,name:"传智播客", page:"http://www.itcast.cn"},
			{id:22,pId:2,name:"百度",page:"http://www.baidu.com"},
			{id:23,pId:2,name:"测试" ,page:"http://www.hao123.com"}
			];
			
			//3.生成菜单；
			$.fn.zTree.init($("#basemenu"), setting,zNodes)
			
			//4，对选项卡注册右键选项卡事件
			$("#mytabs").tabs({
				onContextMenu:function(e,title,index){
					//阻止默认菜单的显示；
					e.preventDefault();
					
					//显示自定义菜单：
					$("#mm").menu('show',{
						left:e.pageX,
						top:e.pageY
					})
					
				}
			});
			
		})
		
		
	</script>
	</head>
	
	<body class ="easyui-layout">
		<div data-options = "region:'north',title:'传智播客管理系统'" style="height: 100px;">北部区域</div>
		<div data-options = "region:'west',title:'菜单导航'" style="width: 180px;">
		<!-- 折叠菜单  -->
			<div id="panel1" class="easyui-accordion" data-options = "fit:true">
				<div data-options = "title:'系统菜单'">
					
				<!-- 通过ztree插件来制作 树形菜单 -->
                	<div>
                		<ul id ="basemenu" class="ztree"></ul>
                	</div>
               
				<!--设置超链接添加一个选显卡-->
				<a href="javascript:void(0)" id ="zcbkLink">传智播客</a>
				</div>
				<div data-options = "title:'基础菜单'">面板二</div>
			</div>
     
		</div>
		<!--
        	中心选项卡
        -->
		<div data-options = "region:'center'">
			<div id = "mytabs" class = "easyui-tabs" data-options = "fit:true">
				<div data-options = "title:'选项卡一'">选项卡一</div>
				<div data-options = "title:'选项卡二', closable:true">选项卡二</div>
			</div>			
		</div>
		
		<div data-options = "region:'east'" style = "width: 80px;">东部区域</div>
		<div data-options = "region:'south'" style="height: 100px;">南部区域</div>
		
		<!--自定义菜单，菜单初始化的隐藏的-->
		<div id="mm" class="easyui-menu" style="width:120px">
			<div>关闭当前选显卡</div>
			<div>关闭其他选显卡</div>
			<div class="menu-sep"></div>
			<div data-options = "iconCls:'icon-Cancel'">关闭所有的选显卡</div>
			
		</div>
	</body>
	
	
</html>
